<template>
  <div class="login">
    <div class="login_form">
      <p>后台管理系统</p>
      <el-tabs v-model="activeName" @tab-click="handleClick" >
        <el-tab-pane label="登录" name="first">
          <el-form
            :model="loginForm"
            ref="loginForm"
            
          >
            <el-form-item label="" prop="account" class="elItem">
              <el-input
                type="text"
                autocomplete="off"
                v-model="loginForm.username"
                prefix-icon="el-icon-user-solid"
                placeholder="请输入用户名"
              ></el-input>
            </el-form-item>
            <el-form-item label="" prop="password">
              <el-input
                type="password"
                autocomplete="off"
                v-model="loginForm.password"
                prefix-icon="el-icon-lock"
                placeholder="请输入密码"
              ></el-input>
            </el-form-item>
            <el-form-item class="btns">
              <el-button type="primary" @click="goToLogin">登录</el-button>
              <el-button @click="resetLoginForm">重置</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="注册" name="second">
            //注册组件
          
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<script>
//引入注册组件
import { login } from "@/components/axios_api/api.js"; // @符号指的是src路径
export default {
  data() {

    return {
        activeName: '',
        loginForm: {
            username: "",
            password: "",}}
      
    },
  methods: {
//固定的账户密码判断实现简单的登录跳转功能，只能测试用
    goToLogin() {
        login(this.loginForm).then((res) => {
          if (res.code == 200) {
            console.log('login', res)
            let resource = res.data.resource_list
            localStorage.setItem('resourcelist', JSON.stringify(resource))
          } else {
            alert('登录失败')
          }
        })
      
    },
    resetLoginForm() {
      this.$refs["loginForm"].resetFields();
    },
    handleClick(){}
  },
  components:{
  }
};
</script>

<style scoped lang='less'>
.login {
  width: 100%;
  height: 100vh;
//   background-image: url("../assets/login/login.jpg");//背景图
  background-size: 100% 100%;
  background-position: center center;
  overflow: auto;
  position: relative;
  .login_form {
    width: 400px;
    height: 360px;
    position: absolute;
    left: 50%;
    top: 25%;
    margin-left: -200px;
    margin-top: -150px;
    padding: 10px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 0 10px #ddd;
    .btns {
      display: flex;
      justify-content: flex-end;
    }
  }
  p {
    font-size: 24px;
    text-align: center;
    font-weight: 600;
  }
}
</style>
